window.workspace = function(){
	var response = <?#$respons?>;
	var layout, myself, agent, astore, agentgrid, mstore, mytask, imgid=Ext.id();
	var pageSize = 10;
	myself = new Ext.form.FormPanel({
		autoWidth	: true,
        labelWidth	: 120,
        fileUpload  : true,
        labelAlign  : 'right',
    	defaults	: {
    		xtype	  : 'textfield'
    	},
    	items		: [{
            xtype		: 'hidden',
            name		: 'id',
            value		: response.user.id
    	},{
            xtype		: 'textfield',
            fieldLabel	: response._L['1000'],
            value		: response.user.account,
            disabled 	: true,
            width		: 72
    	},{
			xtype		: 'textfield',
			inputType 	: 'file', 
	 		fieldLabel	: response._L['1001'],
			name		: 'avtar'
		},{
            xtype		: 'textfield',
            fieldLabel	: response._L['1002'],
            value		: response.user.nickname,
            disabled 	: true,
            width		: 100
    	},{
            xtype		: 'textfield',
            fieldLabel	: response._L['1003'],
            name		: 'loginpw',
            inputType	: 'password',
            regex		: /^[^\s]{6,}$/,
            regexText	: response._L['1004']
    	},{
            xtype		: 'textfield',
            fieldLabel	: response._L['1005'],
            name		: 'email',
            vtype		: 'email',
            value		: response.user.email,
            allowBlank	: false,
            width		: 160
    	},{
            xtype		: 'textfield',
            fieldLabel	: response._L['1006'],
            name		: 'mobile',
            regex		: /^1[34568][0-9]{9}$/,
            regexText   : response._L['1007'], 
            value		: response.user.mobile,
            allowBlank	: false
    	},{
            xtype		: 'datefield',
            fieldLabel	: response._L['1008'],
            format 		: 'Y-m-d',
            value		: response.user.expire,
            disabled 	: true
    	},{
    		xtype		: 'combo',
            store		: new Ext.data.ArrayStore({
	        	fields: ['id','name'],
	        	data: main.cv2Array(response.isdup)
	    	}),
			displayField	: 'name',
			valueField		: 'id',
			mode			: 'local',
			emptyText		: GLang['30015'],
            fieldLabel		: response._L['1010'],
            typeAhead		: true,
            forceSelection	: true,
            width			: 100,
			triggerAction	: 'all',
			allowBlank		: false,
			value			: response.user.isdup,
	    	disabled 		: true,
			hiddenName		: 'isdup',
            name			: 'isdup'
        },{
    		xtype			: 'checkboxgroup',
    		fieldLabel		: response._L['1011'],
            name			: 'roles',
            disabled		: true,
            columns			: 3,
            width			: 360,
			items			: response.mroles
        },{
    		xtype			: 'button',
    		fieldLabel		: '::->',
    		text 			: GLang['30016'],
    		handler			: function(){
    			if(!myself.getForm().isValid())
        			return;
    			myself.getForm().submit({
	        		waitMsg 	: GLang['30017'],
					waitTitle 	: GLang['30003'],
	        		clientValidation: true,
	        		url		: '/admin/myself/dosave.html',
		        	success	: function(form, action) {
		        		if(!!action.result.url) {
		        			document.getElementById(imgid).src = action.result.url;
		        			myself.getForm().findField('avtar').setValue('');
		        		}
		        		Ext.Msg.alert(GLang['30003'], action.result.msg);
					},
					failure	: main.submitFailure
		    	});
    		}
        }]
	});
	agent     = new Ext.form.FormPanel({
        labelWidth	: 120,
        labelAlign  : 'right',
        autoWidth	: true,
    	defaults	: {
    		xtype	  : 'textfield'
    	},
    	items		: [{
    		xtype		: 'checkboxgroup',
    		fieldLabel	: response._L['1011'],
            name		: 'roles',
            id			: 'myselfroles',
            columns		: 3,
            width		: 320,
			items		: response.mroles
        },{
    		xtype		: 'combo',
            store		: new Ext.data.JsonStore({
            	url	: '/admin/share/douser.html',
            	autoDestroy: true,
            	fields: ['id', 'name'],
            	root: 'dataset'
            }),
			displayField	: 'name',
			valueField		: 'id',
			emptyText		: GLang['30015'],
            fieldLabel		: response._L['1017'],
            pageSize		: 10,
            typeAhead		: true,
            width			: 120,
            listWidth		: 258,
            typeAheadDelay  : 0,
            minChars		: 1,
            autoSelect 		: true,
            forceSelection	: true,
			triggerAction	: 'all',
			enableKeyEvents : true,
			allowBlank		: false,
			hiddenName		: 'userid',
			mode			: 'remote',
            name			: 'userid'
        },{
    		xtype		: 'textarea',
    		name		: 'remark',
            fieldLabel	: response._L['1013'],
            maxLength 	: 126, 
            width		: 320,
            height		: 107,
            allowBlank	: false
    	},{
    		xtype		: 'textarea',
            fieldLabel	: response._L['1014'],
            value		: response._L['1015'],
            width		: 360,
            disabled 	: true
    	},{
    		xtype			: 'button',
    		fieldLabel		: '::->',
    		text 			: GLang['30016'],
    		handler			: function(){
    			if(!agent.getForm().isValid())
        			return;
    			agent.getForm().submit({
	        		waitMsg		: GLang['30017'],
					waitTitle 	: GLang['30003'],
	        		clientValidation: true,
	        		url		: '/admin/myself/doagent.html',
		        	success	: function(form, action) {
		        		var items = Ext.getCmp('myselfroles').getValue();
		        		for(var i=0; i < items.length; i++) {
		        			items[i].disable();
		        		}
		        		Ext.Msg.alert(GLang['30003'], action.result.msg);
					},
					failure	: main.submitFailure
		    	});
    		}
        }]
	});
	
	astore = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/myself/agentlog.html',
		autoLoad	: true,
		baseParams	: {
			start	: 0,
			limit	: pageSize
		},
	    root		: 'dataset',
	 	totalProperty: 'total',
	    fields		: ['user', 'agent', 'name', 'stime', 'remark']
	});
	agentgrid = {
		xtype		: 'grid',
	    store		: astore,
	    columns		: [
			{header: response._L['1009'], width:80, sortable:true, dataIndex:'user'},
			{header: response._L['1016'], width:80, dataIndex:'agent'},
			{header: response._L['1017'], width:80, dataIndex:'name'},
			{header: response._L['1018'], width:120, dataIndex:'stime'},
			{header: response._L['1014'], dataIndex:'remark'}
		],
		listeners	: {'render':function(obj){
	    	main.gridRender(obj, ['remark']);
	    }},
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
		height		: 460,
	    stripeRows	: true,
	    bbar		: new Ext.PagingToolbar({
			pageSize	: pageSize,
			store		: mstore,
			displayInfo	: true
		})
	};

	mstore = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/workflow/mytask.json',
		autoLoad	: true,
		baseParams	: {
			start	: 0,
			limit	: pageSize
		},
	    root		: 'dataset',
	 	totalProperty: 'total',
	 	fields		: ['executionid', 'workflow', 'status', 'applyer',  'name', 'expire']
	});
	mytask = {
		xtype		: 'grid',
	    store		: mstore,
		columns		: [
			{header: response._L['1019'], width:60,  sortable:true, dataIndex:'executionid'},
			{header: response._L['1020'], width:140, dataIndex:'workflow'},
			{header: response._L['1021'], width:120, dataIndex:'name'},
			{header: response._L['1022'], width:120, dataIndex:'status'},
			{header: response._L['1023'], width:100, dataIndex:'expire'},
			{header: response._L['1024'], width:100,dataIndex:'applyer'}
		],
		listeners : {
			'rowdblclick': function(grid, index, e){
				var executionid = grid.store.getAt(index).get('executionid');
				var url = "/admin/workflow/executor/id-xxx.html";
				window.open(url.replace('xxx', executionid));
			}
		},
	    viewConfig : {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
		height		: 460,
	    stripeRows	: true,
	    bbar		: new Ext.PagingToolbar({
			pageSize	: pageSize,
			store		: mstore,
			displayInfo	: true
		})
	};
	window.setInterval(function(){
		mstore.reload();
		astore.reload();
    }, 30000);
	var avtar = '<img src="'+response.user.avtar+'" id='+imgid
	+' onerror="this.src=\'/upfile/default/avtar.jpg\';" style="width:120px;height:auto;padding:10px;" />';
	layout= {
		title 		: response.title,
		iconCls 	: 'icon-home',
		closable 	: false,
		region		: 'center',
		xtype		: 'portal',
		margins		: '0 3 0 3',
		border 		: false,
		autoScroll 	: true,
		items		: [{
			columnWidth	: .5,
			style		: 'padding:10px 0 10px 10px',
			items 		: [{
				layout  : 'column', 
				title	: response._L['1025'],
				items	:[{html: avtar, columnWidth	: .2}, {items: myself, columnWidth	: .8}]}, {title : response._L['1026'], items : mytask}]
		}, {
			columnWidth	: .49,
			style		: 'padding:10px 0 10px 10px',
			items 		: [{title : response._L['1027'], items : agent}, {title : response._L['1028'], items : agentgrid}]
		}]
	};
	return layout;
}();